const Service = require('egg').Service

class SecurityService extends Service {
    async msgSecCheck(content, accessToken) {
        const ctx = this.ctx;
        return new Promise(async (resolve, reject) => {
            const result = await ctx.curl(`https://api.weixin.qq.com/wxa/msg_sec_check?access_token=${accessToken}`, {
                dataType: 'json',
                timeout: 5000,
                method: 'POST',
                contentType: "application/json",
                data: JSON.stringify({
                    content
                })
            });
            if(result.status === 200) {
                const { data } = result;
                if(data.errcode === 87014) {
                    reject(new Error('检测到违法违规内容，请修改。'))
                }
            }
            resolve(result)
        })
    }
}

module.exports = SecurityService;